package com.lujianfei.babymilkmemory.ui.history

import android.net.Uri
import androidx.compose.runtime.MutableState
import java.text.SimpleDateFormat
import java.time.LocalDate
import java.util.Calendar
import java.util.Date
import java.util.Locale


/**
 * Author: lujianfei
 * Date: 2025/2/13 18:22
 * Description:
 */

data class HistoryModel(val id:Int, val label:String, val create:Int, var differ:Int = 0, var uri: MutableState<String>) {

    private val weekDays = mapOf(
        Calendar.MONDAY to "周一",
        Calendar.TUESDAY to "周二",
        Calendar.WEDNESDAY to "周三",
        Calendar.THURSDAY to "周四",
        Calendar.FRIDAY to "周五",
        Calendar.SATURDAY to "周六",
        Calendar.SUNDAY to "周日"
    )

    private val calendar = Calendar.getInstance()

    fun getDataString(): String {
        val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault())
        val date = Date(create * 1000L)
        calendar.time = date
        val formattedDate = dateFormat.format(date)
        return "$formattedDate ${weekDays[calendar.get(Calendar.DAY_OF_WEEK)] ?: "未知"}"
    }



    fun getDifferString(): String {
        var sec = differ
        var min = 0
        var hour = 0
        var day = 0
        if (sec >= 60) {
            min = sec / 60
            sec %= 60
        }
        if (min >= 60) {
            hour = min / 60
            min %= 60
        }
        if (hour >= 24) {
            day = hour / 24
            hour %= 24
        }
        return if (day > 0) {
            if (hour > 0) {
                "${day}天${hour}小时"
            } else {
                "${day}天"
            }
        } else if (hour > 0) {
            "${hour}小时"
        } else if (min > 0) {
            "${min}分钟"
        } else {
            "不到1分钟"
        }
    }
}